﻿using Exercises;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Collections.Generic;

namespace ExercisesTest
{


    /// <summary>
    ///This is a test class for ExtensionTest and is intended
    ///to contain all ExtensionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ExtensionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Substring
        ///</summary>
        [TestMethod()]
        public void SubstringTest()
        {
            StringBuilder builder = new StringBuilder("012345678910");
            int index = 4;
            int length = 3;
            string expected = "456";
            string actual;
            actual = builder.Substring(index, length);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Substring
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void SubstringTest1()
        {
            StringBuilder builder = new StringBuilder("0123456789");
            int index = 11;
            int length = 3;
            string expected = "456";
            string actual;
            actual = builder.Substring(index, length);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Substring
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void SubstringTest2()
        {
            StringBuilder builder = new StringBuilder("0123456789");
            int index = 4;
            int length = 20;
            string expected = "456";
            string actual;
            actual = builder.Substring(index, length);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Map
        ///</summary>
        public void MapTestHelper<T>()
        {
            IEnumerable<int> enumerable = new int[] { 1, 2, 3, -10, 2, 100, 5, 8 }; // TODO: Initialize to an appropriate value
            Func<int, int, int> func = Math.Max; // TODO: Initialize to an appropriate value
            int expected = 100; // TODO: Initialize to an appropriate value
            int actual;
            actual = enumerable.Map<int>(func);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void MapTest()
        {
            MapTestHelper<int>();
        }

        /// <summary>
        ///A test for Map
        ///</summary>
        public void MapTest1Helper<T>()
        {
            IEnumerable<int> enumerable = new int[] { 1, 2, 3, -10, 2, 100, 5, 8 };// TODO: Initialize to an appropriate value
            Func<int, int, int> func = Math.Min; // TODO: Initialize to an appropriate value
            int expected = -10; // TODO: Initialize to an appropriate value
            int actual;
            actual = enumerable.Map<int>(func);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void MapTest1()
        {
            MapTest1Helper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for Map
        ///</summary>
        public void MapTest2Helper<T>()
        {
            IEnumerable<int> enumerable = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };// TODO: Initialize to an appropriate value
            Func<int, int, int> func = (x, y) => x + y; // TODO: Initialize to an appropriate value
            int expected = 55; // TODO: Initialize to an appropriate value
            int actual;
            actual = enumerable.Map<int>(func);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void MapTest2()
        {
            MapTest2Helper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for Map
        ///</summary>
        public void MapTest3Helper<T>()
        {
            IEnumerable<int> enumerable = new int[] { 1, 2, 3, 4, 5 };// TODO: Initialize to an appropriate value
            Func<int, int, int> func = (x, y) => x * y; // TODO: Initialize to an appropriate value
            int expected = 120; // TODO: Initialize to an appropriate value
            int actual;
            actual = enumerable.Map<int>(func);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void MapTest3()
        {
            MapTest3Helper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for Map
        ///</summary>
        public void MapTest4Helper<T>()
        {
            IEnumerable<int> enumerable = new int[] {};// TODO: Initialize to an appropriate value
            Func<int, int, int> func = Math.Min; // TODO: Initialize to an appropriate value
            int expected = -10; // TODO: Initialize to an appropriate value
            int actual;
            actual = enumerable.Map<int>(func);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void MapTest4()
        {
            MapTest4Helper<GenericParameterHelper>();
        }
    }
}
